package com.hui.dict;

import androidx.annotation.Nullable;

import android.os.Bundle;
import android.os.PersistableBundle;
import android.util.Log;

import com.hui.dict.bean.PinBuWordBean;
import com.hui.dict.db.DBManager;
import com.hui.dict.utils.CommonUtils;
import com.hui.dict.utils.URLUtils;

import java.util.List;

public class SearchPinyinActivity extends BaseSearchActivity {
    // 获取指定拼音对应的网址
    String url;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initData(CommonUtils.FILE_PINYIN, CommonUtils.TYPE_PINYIN);
        setExLvListener(CommonUtils.TYPE_PINYIN);
        exLv.expandGroup(0);
        // 默认第一个为a
        word = "a";
        url = URLUtils.getPinyinurl(word, page, pagesize);
//        Log.i("SearchPinyinActivity", url);
        // 加载网络数据
        loadData(url);
        setGVListener(CommonUtils.TYPE_PINYIN);
    }

    // 网络获取失败时调用的接口
    @Override
    public void onError(Throwable ex, boolean isOnCallback) {
        List<PinBuWordBean.ResultBean.ListBean> list = DBManager.queryPyWordFromPywordtb(word, page, pagesize);
        refreshDataByGV(list);
    }
}